# -*- coding: utf-8 -*-
# file: car.py
# author: JinTian
# time: 27/03/2017 9:36 AM
# Copyright 2017 JinTian. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------
import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt


data_set_name = 'Car'
train_set_dir = './UCR_TS_Archive_2015/{0}/{0}_TRAIN'.format(data_set_name)
test_set_dir = './UCR_TS_Archive_2015/{0}/{0}_TEST'.format(data_set_name)


def read_data(file_path):
    if os.path.exists(file_path):
        df = pd.read_csv(file_path, sep=',', header=None)
        print('read data success, data shape: ', df.shape)
        print(df.tail(6))

        row_1 = df.iloc[2, :]
        row_2 = df.iloc[3, :]
        plot_2d_same_index([i for i in range(row_1.shape[0])], [row_1, row_2], 'index',
                              ['class_1', 'class_2'])
        plt.show()

    else:
        print('can not find file.')


def plot_2d_same_index(x_index, values, index_label, v_labels):
    assert [len(y) == len(x_index) for y in values], "x y must have same samples."
    assert len(values) == len(v_labels), "horizontal arrays should same with labels."
    for v_label, value in zip(v_labels, values):
        plt.plot(x_index, value)
        plt.xlabel(index_label)
        if len(v_labels) == 1:
            plt.ylabel(v_label)
        else:
            continue
    plt.legend(v_labels)


if __name__ == '__main__':
    read_data(train_set_dir)
